const assert = require('assert');

module.exports = class extends think.Controller {
  constructor(ctx) {
    super(ctx);
    assert(think.isFunction(this.model), 'this.model must be a function');
  }
  async getopenidAction() {
    const { code } = this.post();
    const wechatService = think.service('wechat', code);
    const result = await wechatService.getopenid();
    if (result) {
      this.success(result);
    } else {
      this.fail(result);
    }
  }
  async getaccesstokenAction() {
    const wechatService = think.service('wechat');
    const result = await wechatService.getAccessToken();
    if (result) {
      this.success(result);
    } else {
      this.fail(result);
    }
  }
};
